package com.scqzy.shengchunqiang.sword2offer.day23;

/**
 * @Description: 剑指 Offer 39. 数组中出现次数超过一半的数字
 * @Author 盛春强
 * @Date 2021/8/30 19:06
 */
public class MajorityElement {
    public int majorityElement(int[] nums) {
        int c = 0;
        int t = 0;
        for (int num : nums) {
            if (c == 0) {
                t = num;
                c++;
            } else {
                c += t == num ? 1 : -1;
            }
        }
        return t;
    }
}
